package checkClass;

import java.util.ArrayList;

//构造类型
public class TypeConstructor implements TypeNode {
    //构造类型的类型，数组，函数，记录
    private TypeConstructorEnum type;
    //构造类型的孩子
    private ArrayList<TypeNode> sonList;
    //数组维度
    private int arrayDepth = 0;

    public TypeConstructor(TypeConstructorEnum type, ArrayList<TypeNode> sonList) {
        this.type = type;
        this.sonList = sonList;
    }

    public TypeConstructor(TypeConstructorEnum type, ArrayList<TypeNode> sonList, int arrayDepth) {
        this.type = type;
        this.sonList = sonList;
        this.arrayDepth = arrayDepth;
    }

    public ArrayList<TypeNode> getSonList() {
        return sonList;
    }

    public void setType(TypeConstructorEnum type) {
        this.type = type;
    }

    public TypeConstructorEnum getType() {
        return type;
    }

    //添加一个新孩子
    public void addNewSon(TypeNode typeNode) {
        //可能是空的链表，实例化一下
        if (sonList == null)
            sonList = new ArrayList<>(4);
        sonList.add(typeNode);
    }

    public int getArrayDepth() {
        return arrayDepth;
    }

    public void setArrayDepth(int arrayDepth) {
        this.arrayDepth = arrayDepth;
    }
}
